<?php

class Login extends CI_Controller {
	
	var $msg=null;	// data array	
    public function __construct() {
        parent::__construct("menu");
        $this->load->model('ngonngu_model');
        $this->load->model('menu_model');
        $this->load->model('utility_model');
        $this->load->model('authentication_model');
    }

    public function index() {
        if($this->msg==null) $data['msg'] ="Nhập tài khoản và mật khẩu!";
        else $data['msg']=$this->msg;
        $this->load->view('template/login.html',$data);
    }
    public function verifylogin()
    {
        $this->load->library('form_validation');
		$this->form_validation->set_rules('username', 'Tài khoản', 'xss_clean|required|min_length[5]|max_length[150]');
        $this->form_validation->set_rules('password', 'Mật khẩu', 'xss_clean|required|min_length[5]|max_length[150]');
        if($this->form_validation->run())
        {
        $username = $this->security->xss_clean($this->input->post('username'));
		$password = $this->security->xss_clean($this->input->post('password'));
        echo $username." ".$password;
        if($this->authentication_model->verifyLogin($username,$password)) header('Location:'.site_url());
        else 
            {
                $this->msg="Sai tài khoản hoặc mật khẩu!";
                $this->index();
            }
        }else $this->index();
    }
	

}